using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class TwoPanel : MonoBehaviour
{
    public static TwoPanel Ins;
    private void Awake()
    {
        Ins = this;
    }
    public Transform ToggleGroup, ShopItemGroup, MaxTipePanle, TipePanel;
    public Toggle toggle;
    public Text ToggleText, TipePaneltext;
    int num;
    int toggle_Index;
    string[] strings = new string[] { "元气旅行", "旅行任务", "旅行驿站", "纪念册", "印花商店", "超级旅行家" };
    public List<Transform> AllPanel = new List<Transform>();
    public int MoneyNum, MoveNum;
    public Text MoneyNumText, ButText;
    public bool IsBuy = false;
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < strings.Length; i++)
        {
            ToggleText.text = strings[i];
            int index = i;

            var tog = Instantiate(toggle, ToggleGroup);

            tog.onValueChanged.AddListener((b) =>
            {
                if (b)
                {
                    ChangeToggleData(index);
                }
            });
        }
        toggle.gameObject.SetActive(false);

        ChangeToggleData(0);
    }
    public void BuyBut()
    {
        if (!IsBuy)
        {
            IsBuy = true;

            ButText.text = "已购买";

             MessMgr.GetSinleton().BroadCast("TwoThreePanel");
        }
    }
    private void ChangeToggleData(int index)
    {
        for (int i = 0; i < AllPanel.Count; i++)
        {
            AllPanel[i].gameObject.SetActive(false);
        }
        AllPanel[index].gameObject.SetActive(true);
    }

    // Update is called once per frame
    void Update()
    {
        MoneyNumText.text = "金钱: " + MoneyNum;
         if (TipePanel.gameObject.activeSelf && Input.GetMouseButtonDown(0))
        {
            TipePanel.gameObject.SetActive(false);
        }
    }
}
